package com.atguigu.service.impl;

import com.atguigu.dao.DictDao;
import com.atguigu.entity.Dict;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@DubboService
public class DictServiceImpl implements DictService {
    @Autowired
    private DictDao dictDao;
    @Override
    public List<Map<String, Object>> findZnodes(Long id) {
        List<Dict> list = dictDao.findDictByParentId(id);
        List<Map<String, Object>> zNodes = new ArrayList<>();
        for (Dict dict : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", dict.getId());
            map.put("name", dict.getName());
            map.put("isParent", dictDao.findDictByParentId(dict.getId()).size() > 0);
            zNodes.add(map);
        }
        return zNodes;
    }

    @Override
    public List<Dict> findDictByCode(String code) {
        Long id = dictDao.findIdByCode(code);
        return dictDao.findDictByParentId(id);
    }

    @Override
    public List<Dict> findDictByParentId(Long id) {
        return dictDao.findDictByParentId(id);
    }
}
